package com.example.shardingsphere.common.config;

import com.example.shardingsphere.common.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyRabbitMQConfig {
    /**
     * 创建一个名称为directQueue的可持久化队列
     *
     * @return
     */
    @Bean("directQueue")
    public Queue directQueue1() {
        return QueueBuilder.durable(Constants.DIRECT_SHUZIMALI_QUEUE).build();
    }
    /**
     * 创建一个名称为directExchange的路由交换机
     *
     * @return
     */
    @Bean("directExchange")
    public DirectExchange directExchange() {
        return ExchangeBuilder.directExchange(Constants.DIRECT_SHUZIMALI_EXCHANGE).durable(true).build();
    }
    /**
     * 将directQueue1绑定到directExchange交换机 路由键为orange
     *
     * @return
     */
    @Bean
    public Binding directBinding(@Qualifier("directExchange") DirectExchange directExchange,
                                  @Qualifier("directQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(directExchange).with("shuzimali");
    }
}
